<?php

class Model_Behavior_Formatter_Dict {

    static function get($obj, $prop, $config, & $props) {
        $dict = isset($config['dict']) ? $config['dict'] : $config[1];
        $prop_name = $config['prop_name'];
        $value = $props[$prop_name];
        return $dict[$value];
    }

    static function set($obj, $value, $prop, $config, & $props) {
        $prop_name = $config['prop_name'];
        $dict = isset($config['dict']) ? $config['dict'] : $config[1];
        $dict = array_flip($config['dict']);
        if (isset($dict[$value])) {
            $props[$prop_name] = $dict[$value];
            $obj->willChanged($prop_name);
        }
    }

}